# 2024/1/30 14:48 HFL
import hashlib

import requests, json, re

from common import pinjiecomment
from common.MD5 import md5
from common.pinjiecomment import pinjie

url = 'http://127.0.0.1:8999/stock/producttoken'

result = requests.get(url)
# 使用JSON提取器
res = json.loads(result.text)
print(res['msg'])

# 使用正则表达式
url2 = 'http://127.0.0.1:8999/stock/producttoken'
res2 = requests.get(url2)
result2 = re.findall('"msg": "(.*?)"', res2.text)
print(result2[0])

url3 = 'http://127.0.0.1:8999/stock/asynRecharge'
# token = "token=" + result2[0] + "&orderId=2017020100002104204264aa5f6&count=2&productCode=sp0001024&notifyUrl=http://xx&key=123456"
# sign = md5(token)
# print(sign)

data = {
    "token": result2[0],
    "orderId": "2017020100002104204264aa5f6",
    "count": 2,
    "productCode": "sp0001024",
    "notifyUrl": "http://xx",
    "sign": ''
}
print(pinjie(data))

data['sign'] = md5(pinjie(data))



headers = {'Content-Type': 'application/json'}
res3 = requests.post(url=url3, json=data, headers=headers)
res3.encoding = 'unicode-escape'
print(res3.text)
